A ring buffer, also known as a circular buffer, circular queue, or cyclic buffer, is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. The ring buffer structure improves the buffering of data streams. Generally, a ring buffer does not need to have its elements shuffled around when one is consumed. A ring buffer is well-suited as a first-in first-out (FIFO) buffer.
Ring buffers may be designed to be on-chip or off-chip. On-chip ring buffers exhibit fast write/read times but have limited size (e.g., once the size is consumed, on-chip ring buffers stall with no free space). Off-chip ring buffers have larger sizes but exhibit slower access speed due to the use of a Layer 2 (L2) cache or off-chip memory to store data.
In operation, a ring buffer has a write and read pointer. A consequence of the circular buffer is that when it is full and a subsequent write is performed, then it starts overwriting the oldest data. A circular buffer can be implemented using pointers or indices for the buffer start in memory, buffer end in memory, or buffer capacity, start of valid data, and end of valid data, or amount of data currently in the buffer.
When an element is written, the start pointer is incremented to the next element. In the pointer-based implementation strategy, the buffer's full or empty state can be resolved from the start and end indexes. When the start and end indexes are equal, the buffer is empty. When the start index is one greater than the end index, the buffer is full. Alternatively, if the buffer is designed to track the number of inserted elements n, checking for emptiness means checking n=0 and checking for fullness means checking whether n equals the capacity.
Ring buffers are broadly used in ASIC design. Size and access performance are two major concerns to ring buffer design and use. Larger sizes can decouple the data producer and the consumer, but at the cost of access (read/write) speed and integrated circuit area. Therefore, a need exists for an improved ring buffer design.